package com.fjwt.gz.proxy.ctrl.award.virtual;


import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.entity.SysUser;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.AwardVirtualSupplierDTO;
import com.fjwt.gz.db.vo.AwardVirtualSupplierVO;
import com.fjwt.gz.proxy.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AwardVirtualSupplierService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 虚拟奖品供应商管理
 *
 */
@RestController
@Slf4j
@RequestMapping("/api/awardVirtual/supplier")
public class AwardVirtualSupplierController extends CommonCtrl {

    @Autowired
    private AwardVirtualSupplierService awardVirtualSupplierService;

    /**
     * 查询供应商列表
     * @return
     */
    @GetMapping
    public ApiRes list() {
        AwardVirtualSupplierDTO supplierDTO = getObject(AwardVirtualSupplierDTO.class);
        log.info("机构端查询供应商列表接口调用，请求地址：/api/awardVirtual/supplier，请求参数：{}", JSONUtil.toJsonStr(supplierDTO));
        IPage<AwardVirtualSupplierVO> page = awardVirtualSupplierService.queryList(getIPage(true), supplierDTO);
        log.info("机构端查询供应商列表接口返回结果：{}", JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }


    /**
     * 新增供应商
     * @return
     */
    //@PreAuthorize("hasAnyAuthority('ENT_VIRTUAL_GOODS_SUPPLIER_ADD')")
    @PostMapping("/add")
    public ApiRes add() {
        AwardVirtualSupplierDTO supplierDTO = getObject(AwardVirtualSupplierDTO.class);
        log.info("机构端新增供应商接口调用，请求地址：/api/awardVirtual/supplier/add，请求参数：{}", JSONUtil.toJsonStr(supplierDTO));
        // 当前登录用户信息
        SysUser sysUser = getCurrentUser().getSysUser();
        awardVirtualSupplierService.addSupplier(supplierDTO, sysUser.getSysUserId());
        return ApiRes.ok();
    }

    /**
     * 修改供应商信息
     * @return
     */
    //@PreAuthorize("hasAnyAuthority('ENT_VIRTUAL_GOODS_SUPPLIER_EDIT')")
    @PostMapping("/update")
    public ApiRes update() {
        AwardVirtualSupplierDTO supplierDTO = getObject(AwardVirtualSupplierDTO.class);
        log.info("机构端修改供应商信息接口调用，请求地址：/api/awardVirtual/supplier/update，请求参数：{}", JSONUtil.toJsonStr(supplierDTO));
        awardVirtualSupplierService.updateSupplier(supplierDTO);
        return ApiRes.ok();
    }

    /**
     * 更新状态信息
     * @return
     */
    @PostMapping("/updateState")
    public ApiRes updateState() {
        AwardVirtualSupplierDTO supplierDTO = getObject(AwardVirtualSupplierDTO.class);
        awardVirtualSupplierService.updateStateById(supplierDTO);
        return ApiRes.ok();
    }

    /**
     * 拉取供应商商品信息
     * @return
     */
    // @PreAuthorize("hasAnyAuthority('ENT_VIRTUAL_GOODS_SUPPLIER_EDIT')")
    @PostMapping("/getGoodsList")
    public ApiRes getGoodsList() {
        AwardVirtualSupplierDTO supplierDTO = getObject(AwardVirtualSupplierDTO.class);
        log.info("机构端拉取供应商商品信息接口调用，请求地址：/api/awardVirtual/supplier/getGoodsList，请求参数：{}", JSONUtil.toJsonStr(supplierDTO));
        awardVirtualSupplierService.getGoodsList(supplierDTO);
        return ApiRes.ok();
    }

    /**
     * 设置供应商商品回调地址
     */
    @PostMapping(value = "/setGoodsNotifyUrl")
    public ApiRes setGoodsNotifyUrl() {
        AwardVirtualSupplierDTO supplierDTO = getObject(AwardVirtualSupplierDTO.class);
        log.info("机构端设置供应商商品回调地址接口调用，请求地址：/api/awardVirtual/supplier/setGoodsNotifyUrl，请求参数：{}", JSONUtil.toJsonStr(supplierDTO));
        awardVirtualSupplierService.setGoodsNotifyUrl(supplierDTO);
        return ApiRes.ok();
    }
}
